package com.test.controller;

import com.test.domain.Dish;
import com.test.domain.Result;
import com.test.domain.Utils;
import com.test.service.ChoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/choice")
public class ChoiceController {

    private final ChoiceService choiceService;

    @Autowired
    public ChoiceController(ChoiceService choiceService) {
        this.choiceService = choiceService;
    }




    @GetMapping("/chooseDish")
    public Result chooseDish(@RequestParam("customerPhoneNumber") String customerPhoneNumber,
                             @RequestParam("dishNumber") String dishNumber){
        choiceService.chooseDish(customerPhoneNumber,dishNumber);
        return Utils.success("ok");

    }

    @GetMapping("/getChoiceList")
    public Result getChoiceList(@RequestParam("customerPhoneNumber") String customerPhoneNumber){
        System.out.println(customerPhoneNumber);
        return Utils.success(choiceService.getChoiceList(customerPhoneNumber));
    }

    @GetMapping("/subNum")
    public Result subNum(@RequestParam("customerPhoneNumber") String customerPhoneNumber,
                         @RequestParam("dishNumber") String dishNumber){
        choiceService.subNum(customerPhoneNumber,dishNumber);
        return Utils.success("ok");

    }

    @GetMapping("/delete")
    public Result deleteChoice(@RequestParam("dishNumber") String dishNumber,
                               @RequestParam("customerPhoneNumber") String customerPhoneNumber){
        choiceService.deleteChoice(customerPhoneNumber,dishNumber);
        return Utils.success("ok");
    }

    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestParam("wholePrice")BigDecimal wholePrice,
                              @RequestParam("accountNumber")String accountNumber,
                              @RequestParam("phoneNumber") String phoneNumber,
                              @RequestParam("allAddress") String allAddress,
                              @RequestBody List<String> dishList) throws InterruptedException {

        choiceService.createOrder(wholePrice,accountNumber,phoneNumber,allAddress,dishList);

        return Utils.success("ok");
    }



}
